
function Get-CMPackage
{
<#
.Synopsis
    Returns a package, or all instances of a package.
.Description
    Returns a package, or all instances of a package.
.Parameter SiteServerName 
    ConfigMgr Site Server Name
.Parameter PackageID
    Enter PackageID    
.Parameter Credential 
    Enter Alternate Credentials if required
.Example
    Get-CMPackage
.Example
    Get-CMPackage MYTESTLABServer
        Returns all instances of the SMS_Package Class on MYTESTLABServer
.Example
    Get-CMPackage MYTESTLABServer LAB00012 
        Returns package LAB00012 on MYTESTLABServer
.Example
    Get-CMPackage MYTESTLABServer LAB00012 get-credential
        Prompts for credentials
.Example
    Get-CMPackage MYTESTLABServer LAB00012 $Cred
        uses credentials in $Cred
.Outputs
    Returns either an instance, or multiple instances from the SMS_Package Class
.Link
    http://msdn.microsoft.com/en-us/library/cc144959.aspx
.Notes
 NAME:      Get-CMPackage
 AUTHOR:    Greg Ramsey
 LASTEDIT:  08/07/2009 00:39:05
#Requires -Version 2.0
#>

[CmdletBinding(
    SupportsShouldProcess=$False,
    SupportsTransactions=$False, 
    ConfirmImpact="None",
    DefaultParameterSetName="")]
param(
[Parameter(Position=0)]
[String]$ComputerName="." ,

[Parameter(Position=1)]
[String]$PackageID ,

[Parameter(Position=2)]
[String]$Filter ,

[Parameter(Position=3)]
$Credential
)

Begin
{
}#Begin

Process
{
    get-cmobject -class SMS_Package -ComputerName $ComputerName -Filter $Filter -Credential $Credential | ? {$_.PackageID -like ($PackageID + "*")}
}#Process

End
{
}#End
}


function New-CMPackage
{
<#
.Synopsis
    Creates a new ConfigMgr Package.
.Description
    Creates a new ConfigMgr Package.
.Parameter SiteServerName 
    ConfigMgr Site Server Name
.Parameter Name
    Enter Package Name    
.Parameter Version
    Enter Package Version
.Parameter Manufacturer
    Enter Package Manufacturer
.Parameter Description
    Enter Package Description
.Parameter DataSource
    Enter Package Data Source Path  
.Example
    New-CMPackage
.Example
    New-CMPackage MYTESTLABServer
        Returns all instances of the SMS_Package Class on MYTESTLABServer
.Example
    New-CMPackage MYTESTLABServer "ConfigMgr Toolkit" -Description "ConfigMgr ToolKit Package for all Platforms" -DataSourcePath "\\cm02\source$\ConfigMgrToolkit"
.Outputs
    Returns the new package instance from the SMS_Package Class
.Link
    http://msdn.microsoft.com/en-us/library/cc144959.aspx
.Notes
 NAME:      New-CMPackage
 AUTHOR:    Greg Ramsey
 LASTEDIT:  08/07/2009 00:39:05
#Requires -Version 2.0
#>

[CmdletBinding(
    SupportsShouldProcess=$False,
    SupportsTransactions=$False, 
    ConfirmImpact="None",
    DefaultParameterSetName="")]
param(
[Parameter(Position=0)]
[String]$ComputerName="." ,

[Parameter(Position=1, Mandatory=$true, HelpMessage="Enter Package Name")]
[String]$Name ,

[Parameter(Position=2)]
[String]$Version=$Null ,

[Parameter(Position=3)]
[String]$Manufacturer=$Null ,

[Parameter(Position=4)]
[String]$Description=$null ,

[Parameter(Position=5, Mandatory=$true, HelpMessage="Enter Package Source Path")]
[String]$DataSourcePath
)

Begin
{
}#Begin

Process
{
    $oSite = Connect-CMProvider -Computer $ComputerName -Credential $Credential
    $NS = "Root\SMS\Site_" + $oSite.SiteCode
    $pkgclass = [WMIClass] "\\$($ComputerName)\$($NS):SMS_Package"
    $newPkg = $pkgclass.CreateInstance()
    $NewPkg.Name = $Name
    $newPkg.Version = $Version
    $newPkg.Manufacturer = $Manufacturer
    $newPkg.Description = $Description
    $newPkg.PkgSourcePath = $DatasourcePath
    $newPkg.PkgSourceFlag = 2
    $newPkg.Put()
    $newPkg.Get()
    $newPkg
    }#Process

End
{
}#End
}

function Get-CMProgram
{
<#
.Synopsis
    Returns a program, or all program instances.
.Description
    Returns a program, or all program instances.
.Parameter SiteServerName 
    ConfigMgr Site Server Name
.Parameter PackageID
    Enter PackageID    
.Parameter ProgramName
    Enter ProgramName
.Parameter Credential 
    Enter Alternate Credentials if required
.Example
    Get-CMProgram
.Example
    Get-CMProgram MYTESTLABServer
        Returns all instances of the SMS_Program Class on MYTESTLABServer
.Example
    Get-CMProgram MYTESTLABServer LAB00012 
        Returns all programs for PackageID LAB00012 on MYTESTLABServer
.Example
    Get-CMProgram MYTESTLABServer LAB00012 get-credential
        Prompts for credentials
.Example
    Get-CMProgram MYTESTLABServer LAB00012 $Cred
        uses credentials in $Cred
.Outputs
    Returns either an instance, or multiple instances from the SMS_Package Class
.Link
    http://msdn.microsoft.com/en-us/library/cc144361.aspx
.Notes
 NAME:      Get-CMProgram
 AUTHOR:    Greg Ramsey
 LASTEDIT:  08/07/2009 00:39:05
#Requires -Version 2.0
#>

[CmdletBinding(
    SupportsShouldProcess=$False,
    SupportsTransactions=$False, 
    ConfirmImpact="None",
    DefaultParameterSetName="")]
param(
[Parameter(Position=0)]
[String]$ComputerName="." ,

[Parameter(Position=1)]
[String]$PackageID ,

[Parameter(Position=2)]
[String]$ProgramName ,

[Parameter(Position=3)]
[String]$Filter ,

[Parameter(Position=4)]
$Credential
)

Begin
{
}#Begin

Process
{
    get-cmobject -class SMS_Program -ComputerName $ComputerName -Filter $Filter -Credential $Credential | ? {$_.PackageID -like ($PackageID + "*") -and $_.ProgramName -like ($ProgramName + "*") }
}#Process

End
{
}#End
}

function New-CMProgram
{
<#
.Synopsis
    Creates a new ConfigMgr Program.
.Description
    Creates a new ConfigMgr Program.
.Parameter SiteServerName 
    ConfigMgr Site Server Name
.Parameter PackageID
    Enter PackageID
.Parameter ProgramName
    Enter ProgramName    
.Parameter CommandLine
    Enter Command Line
.Example
    New-CMProgram
        Prompts for required information.
.Example
    New-CMProgram MYTESTLABServer LAB00023
        Creates a new Program for PackageID=LAB00023 on the site server MYTESTLABServer
.Example
    New-CMProgram MYTESTLABServer LAB00023 "Silent Install" "CCMTools.msi /passive /norestart"
.Outputs
    Returns the new Program instance from the SMS_Program Class
.Link
    http://msdn.microsoft.com/en-us/library/cc144361.aspx
.Notes
 NAME:      New-CMProgram
 AUTHOR:    Greg Ramsey
 LASTEDIT:  08/07/2009 00:39:05
#Requires -Version 2.0
#>

[CmdletBinding(
    SupportsShouldProcess=$False,
    SupportsTransactions=$False, 
    ConfirmImpact="None",
    DefaultParameterSetName="")]
param(
[Parameter(Position=0)]
[String]$ComputerName="." ,

[Parameter(Position=1, Mandatory=$true, HelpMessage="Enter PackageID")]
[String]$PackageID ,

[Parameter(Position=2, Mandatory=$true, HelpMessage="Enter Program Name")]
[String]$ProgramName=$Null ,

[Parameter(Position=3, Mandatory=$true, HelpMessage="Enter Command Line")]
[String]$CommandLine=$Null 
)

Begin
{
}#Begin

Process
{
    $oSite = Connect-CMProvider -Computer $ComputerName -Credential $Credential
    $NS = "Root\SMS\Site_" + $oSite.SiteCode
    $prgclass = [WMIClass] "\\$($ComputerName)\$($NS):SMS_Program"
    $newPrg = $prgclass.CreateInstance()
    $newPrg.PackageID = $packageID
    $newPrg.ProgramName = $ProgramName
    $newPrg.CommandLine = $CommandLine
    $newPrg.Put()
    $newPrg.Get()
    $newPrg
    }#Process

End
{
}#End
}


